package code.example.zookeeper.base.command.read;

import code.example.zookeeper.ZookeeperHolder;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Exists  {
    private Logger logger = LoggerFactory.getLogger(Exists.class);
    ZookeeperHolder holder = null;
    public Exists(ZookeeperHolder holder ){
        this.holder = holder;
    }
    public void existForWatcher(String path ,Watcher watcher) throws Exception {
        logger.info("[exist]:register watcher for path:"+path);
        exist(path,watcher);
    }

    public boolean  exist(String path, Watcher watcher) throws Exception{
        Stat stat =  this.holder.getInstance().exists(path,watcher);
        if(stat == null){
            return false;
        }else{
            return true;
        }
    }

}
